import NProgress from "nprogress";
import "nprogress/nprogress.css";
import { message } from "ant-design-vue";
import {
	registerMicroApps,
	addGlobalUncaughtErrorHandler,
	start,
} from "qiankun";
import apps from "./app.js";

// 注册微应用
registerMicroApps(apps, {
	beforeLoad: (app) => {
		NProgress.start();
	},
	afterMount: (app) => {
		NProgress.done();
	},
});

addGlobalUncaughtErrorHandler((event) => {
	console.error(event);
	const { message: msg } = event;
	if (msg && msg.includes("died in status LOADING_SOURCE_CODE)")) {
		message.error("微应用加载失败，请检查应用是否可运行");
	}
});

// 导出 qiankun 的 start 方法，用于启动 qiankun 主应用
export default start;
